package com.shadowtorcher.soulknife.util;
/*
 * Copyright (C)  li, Shadow Torcher project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.PrintStream;
import java.util.TreeMap;

public class Logger extends java.util.logging.Logger {
    public static final int ERROR = 1;
    public static final int WARN = 2;
    public static final int DEBUG = 3;
    public static final int INFO = 4;
    public static final TreeMap map = new TreeMap<String, Integer>() {{
        put("ERROR", ERROR);
        put("WARN", WARN);
        put("DEBUG", DEBUG);
        put("INFO", INFO);
    }};

    private static PrintStream printStream = System.err;
    private static int logLevel = INFO;

    protected Logger(String s, String s1) {
        super(s, s1);
    }

    public static void setLogLevel(Object logLevel) {
        logLevel = map.get(logLevel);
    }

    public static void logE(String str) {
        if (logLevel >= ERROR)
            printStream.println("[ERROR] " + str);
    }

    public static void logW(String str) {
        if (logLevel >= WARN)
            printStream.println("[WARN ] " + str);
    }

    public static void logD(String str) {
        if (logLevel >= DEBUG)
            printStream.println("[DEBUG] " + str);
    }

    public static void logI(String str) {
        if (logLevel >= INFO)
            printStream.println("[INFO ] " + str);
    }
}
